<?php

namespace app\admin\controller;

use app\common\controller\AdminBaseController;

class GroupController extends AdminBaseController
{
    protected function initialize()
    {
        parent::initialize();
        $this->server = model('server.group');
    }

    public function getGroupListOp()
    {
        $responseData['meta'] = ['code' => 1, 'msg' => lang('GET_SUCCESS')];
        $responseData['data'] = $this->server->getTree('');

        return $responseData;
    }

    public function saveGroupAddOp()
    {
        $requestData = validateRequestParam('group', 'saveAdd');
        $responseData['meta'] = ['code' => 1, 'msg' => lang('SAVE_SUCCESS')];
        $responseData['data'] = $this->server->saveAdd($requestData);

        return $responseData;
    }

    public function getGroupRowOp()
    {
        $postData = validateRequestParam('group', 'getRow');
        $responseData['meta'] = [
            'code' => 1,
            'msg' => lang('GET_SUCCESS'),
        ];
        $responseData['data'] = $this->server->getRow($postData);

        return $responseData;
    }

    public function saveGroupEditOp()
    {
        $postData = validateRequestParam('group', 'saveEdit');
        $responseData['meta'] = [
            'code' => 1,
            'msg' => lang('SAVE_SUCCESS'),
        ];
        $responseData['data'] = $this->server->saveEdit($postData);

        return $responseData;
    }

    public function saveGroupDelOp()
    {
        $postData = validateRequestParam('group', 'saveEdit');
        $responseData['meta'] = [
            'code' => 1,
            'msg' => lang('DEL_SUCCESS'),
        ];
        $responseData['data'] = $this->server->saveDel($postData);

        return $responseData;
    }

    public function getGroupPowerOp()
    {
        $postData = validateRequestParam('group', 'getRow');
        $responseData['meta'] = [
            'code' => 1,
            'msg' => lang('GET_SUCCESS'),
        ];
        $responseData['data'] = $this->server->getPower($postData);

        return $responseData;
    }

    public function saveGroupPowerOp()
    {
        $postData = validateRequestParam('group', 'savePower');
        $responseData['meta'] = [
            'code' => 1,
            'msg' => lang('GET_SUCCESS'),
        ];
        $responseData['data'] = $this->server->savePower($postData);

        return $responseData;
    }

    public function getTreeGroupAllOp()
    {
        $data['status'] = 1;
        $responseData['meta'] = ['code' => 1, 'msg' => lang('GET_SUCCESS')];
        $responseData['data'] = $this->server->getTree($data);

        return $responseData;
    }

    public function getGroupPowerAllOp()
    {
        $data['status'] = 1;
        $data['type'] = 2;
        $responseData['meta'] = ['code' => 1, 'msg' => lang('GET_SUCCESS')];
        $responseData['data'] = $this->server->getTree($data);

        return $responseData;
    }
}
